package com.tencent.sr.iris.activity.service.event.handler;

import com.tencent.sr.iris.activity.domain.event.dto.ActivityDTO;
import com.tencent.sr.iris.activity.domain.event.dto.ActivityTaskDTO;
import com.tencent.sr.iris.activity.interfaces.event.dto.ActivityEventDTO;
import com.tencent.sr.iris.activity.service.activity.IrisActivityService;
import com.tencent.sr.iris.activity.service.event.activity.IrisActivityExecutor;
import java.util.List;
import java.util.Objects;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 用户打特邀标事件处理
 *
 * @author xiaojun
 */
@Slf4j
@Component("SPECIAL_INVITE")
public class SpecialInviteEventHandler extends AbstractIrisEventHandler {

    @Resource
    private IrisActivityService activityService;

    @Override
    public void after(ActivityEventDTO eventDTO) {

    }

    @Override
    void process(ActivityEventDTO eventDTO, List<String> eventHandingInfoList) {
        //补充pid
        addParameterForEvent(eventDTO);
        ActivityDTO activity = getActivity(eventDTO);
        IrisActivityExecutor activityExecutor = getActivityExecutor(eventDTO, activity);
        activityExecutor.execute(eventDTO, activity);
        eventHandingInfoList.add(this.getClass().getSimpleName() + "处理成功,idempotent:" + eventDTO.getIdempotent());
    }


    @Override
    List<ActivityTaskDTO> getRelatedTaskList(String eventType) {
        return null;
    }

    @Override
    void baseDataProcess(ActivityEventDTO eventDTO) {

    }

    protected ActivityDTO getActivity(ActivityEventDTO msg) {
        // 查询活动信息
        ActivityDTO activity = activityService.getActivity(activityConfig.getSpecialInviteGiftActivityId());
        if (Objects.isNull(activity)) {
            log.error("未查询到特邀邀请有礼活动信息,activityBizId={}", activityConfig.getSpecialInviteGiftActivityId());
            return null;
        }
        return activity;
    }
}
